package service

import (
	"encoding/json"
	"gitee.com/sansaniot/ssiot-core/httpmvc/service"
	"ssadmin/common/utils"
	"ssadmin/internal/admin/models"
)

type SysApi struct {
	service.Service
}

// 查询api分组树结构
func (e *SysApi) GetTree() (error, []map[string]interface{}) {
	//查询所有的api列表集合
	err, list := (&models.SysApi{}).FindApiList(e.Orm)
	//是否查询成功
	if err == nil {
		//转化为map对象
		data, _ := json.Marshal(&list)
		dataMap := make([]map[string]interface{}, 0)
		_ = json.Unmarshal(data, &dataMap)

		//树结构处理
		return nil, utils.ConvrtListToTree(dataMap, "id")
	}
	return err, nil
}
